#include "pthread_impl.h"

int __pthread_mutex_setprioceiling(pthread_mutex_t *restrict m, int prioceiling, int *restrict old)
{
    int ret;
    int retLock;
    if ((m == NULL) || (prioceiling < PTHREAD_PRIORITY_HIGHEST) || (prioceiling > PTHREAD_PRIORITY_LOWEST)) {
        return EINVAL;
    }

    retLock = __pthread_mutex_timedlock(m, PTHREAD_WAIT_FOREVER);
    if (retLock != 0) {
        return retLock;
    }

    if (old != NULL) {
        *old = (m->_m_type >> 8 ) & 0x000000ff;
    }

    ret = pthread_mutexattr_setprioceiling(&m->_m_type, prioceiling);

    retLock = __pthread_mutex_unlock(m);
    if ((ret == 0) && (retLock != 0)) {
        return retLock;
    }

    return 0;
}

weak_alias(__pthread_mutex_setprioceiling, pthread_mutex_setprioceiling);
